package de.tum.in.eist.poll.server;

import java.util.ArrayList;
import java.util.List;


import de.tum.in.eist.poll.shared.Poll;
import de.tum.in.eist.poll.shared.Student;
import de.tum.in.eist.poll.shared.exceptions.UserNotFoundException;

public class Database {
	public static final UserDatabaseManager userDatabase = new UserDatabaseManager();
	public static final PollDatabaseManager pollDatabase = new PollDatabaseManager();
	
	
	public static Student updateUser(Student u) throws UserNotFoundException{
		List<Poll> submittedPolls = u.getSubmittedPolls();
		List<Poll> openPolls = pollDatabase.getOpenPolls();
		List<Poll> newSubmitted = new ArrayList<Poll>();
		List<Poll> newAvailable = new ArrayList<Poll>();
		
		
		submittedPolls.retainAll(openPolls);
		openPolls.removeAll(submittedPolls);
		u.setSubmittedPolls(newSubmitted);
		u.setAvailablePolls(newAvailable);
		userDatabase.updateUser(u);
		return u;
	}


}
